date_trans <- function(x = ""){
  library(stringr)
  if(grepl(x = x, pattern = "4\\d\\d\\d\\d")){
    #41234
    cat(x, "\n")
    cat(as.character(as.Date("1900-01-01") + as.numeric(x) - 2), "\n")
    return(as.character(as.Date("1900-01-01") + as.numeric(x) - 2))
  }else if(grepl(x = x, pattern = "\\.")){
    length_temp <- str_locate_all(string = x, pattern = "\\.")
    if(dim(length_temp[[1]])[1] == 2){
      # 2001.01.01
      date_temp <- str_extract(string = x, pattern = "\\d{2,4}\\.\\d{1,2}\\.\\d{1,2}")
      date_out <- str_replace_all(string = date_temp, pattern = "\\.", replacement = "-")
      cat(x, "\n")
      cat(date_out, "\n")
      return(as.character(as.Date(date_out)))
    }else if(dim(length_temp[[1]])[1] == 1){
      # 2001.01.01
      date_temp <- str_extract(string = x, pattern = "\\d{2,4}\\.\\d{1,2}")
      date_out <- paste(str_replace_all(string = date_temp, pattern = "\\.", replacement = "-"), "-01", sep = "")
      cat(x, "\n")
      cat((date_out), "\n")
      return(as.character(as.Date(date_out)))
    }
  }else{
    cat("cannot recongnize\n")
    return(x)
  }
}

#### Test Area ####

# date_trans("41000")
# date_trans(x = "2021.01.01")
# date_trans(x = "2021.01")
